#pragma once
#include "DataPreprocessor.h"
#include "PatternCalibrationProcess.h"
#include "VerticesConstructor.h"
#include "RegisterationProcess.h"
#include "OctreeConstructor.h"
#include "SurfaceExtractProcess.h"
#include <vector>

class ReconstructProcess
{
public:
	ReconstructProcess ();
	~ReconstructProcess ();

	void initialize ();
	void clean ();
	void addSensor (SensorDataInput *pSensor);
	const SensorDataInput *getSensor (size_t index) const;
	SensorDataInput *getSensor (size_t index);
	size_t getSensorsCount () const;

	bool grabNewFrameAndProcess ();

	const ID3D11Buffer *getVerticesForVisualDxBufPtr () const;
	ID3D11Buffer *getVerticesForVisualDxBufPtr ();

	const ID3D11Buffer *getPVertexPairsForVisualDxRawBuf (size_t index) const;
	ID3D11Buffer *getPVertexPairsForVisualDxRawBuf (size_t index);

	Octree *getOctreePtr ();
	ID3D11Buffer *getModelVerticesDxBufPtr ();
	ID3D11Buffer *getModelTrianglesDxBufPtr ();

private:

	UINT _maxVerticesCount;
	UINT _frameCount;
	std::vector< SensorDataInput * > _sensorPtrs;
	std::vector< SensorResource > _sensorResources;
	std::vector< ID3D11Buffer * > _vertexPairsForVisualDxRawBufPtrs;
	QD3DResourcePack *_p_verticesPack;
	ID3D11Buffer *_p_verticesForVisualDxBuf;
	Octree *_p_octree;
	QD3DResourcePack *_p_modelVerticesPack;
	QD3DResourcePack *_p_modelTrianglesPack;

	DataPreprocessor _dataProcessor;
	PatternCalibrationProcess _calibrator;
	VerticesConstructor _verticesConstructor;
	RegisterationProcess _registerationProcessor;
	OctreeConstructor _octreeConstructor;
	SurfaceExtractProcess _surfaceExtractProcess;

	void _grabFrame ();
	void _preprocess ();
	void _estimateTransform ();
	void _constructOctree ();
	void _extractSurface ();
	void _clearOctree ();
};